package com.util;

import java.util.List;

/**
 * 分页助手
 * @param <T>
 */
public class PageAssistant<T> {

    /* 总记录数: 总共多少条数据 */
    private int count;
    /* 总页数, 通过内部计算获取 */
    private int totalPage;
    /* 页码: 当前页 */
    private int currPage = 1;
    /* 页面大小: 每页显示的数据条数 */
    private int pageSize = 5;
    /* 初始记录序号: 从哪条数据开始, 通过内部计算获取 */
    private int start;

    @Override
    public String toString() {
        return "PageAssistant{" +
                "count=" + count +
                ", totalPage=" + totalPage +
                ", currPage=" + currPage +
                ", pageSize=" + pageSize +
                ", start=" + start +
                '}';
    }

    /* 页面内容集合 */
    private List<T> items;

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
        setTotalPage();
    }

    public int getTotalPage() {
        return totalPage;
    }

    private void setTotalPage() {
        this.totalPage = count / pageSize;
        if (count % pageSize != 0){
            totalPage++;
        }
    }

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage;
        setStart();
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        setTotalPage();
        setStart();
    }

    public int getStart() {
        return start;
    }

    private void setStart() {
        this.start = (currPage - 1) * pageSize;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }
}
